$(function() {
	var options = {
		useEasing: true,
		useGrouping: true,
		separator: '',
		decimal: '.',
		prefix: '',
		suffix: ''
	};
	var moneyStart1, moneyEnd1, count1,
		moneyStart2, moneyEnd2, count2,
		moneyStart3, moneyEnd3, count3;
	var tr, date, year, month, day, hour, minute, second;
	var donutM;
	var data = [{
		label: "充值",
		value: 130
	}, {
		label: "提现",
		value: 200.3
	}, {
		label: "交易",
		value: 500.34
	}];

	var getCurrentDate = function() {
		date = new Date();
		year = date.getFullYear();
		month = date.getMonth() + 1;
		day = date.getDate();
		hour = date.getHours();
		minute = date.getMinutes();
		second = date.getSeconds();
	};
	getCurrentDate();
	$('.now').text(year + '.' + month + '.' + day + ' ' + hour + ':' + minute + ':' + second);

	// 绘图
	var donut = function() {
		donutM = Morris.Donut({
			element: 'donut-main',
			data: data,
			colors: ['#EF8100', '#FEC99B', '#FFAA62', '#A85623', '#C14E00']
		});
	};
	donut();

	// 充值
	$('body').on('click', '.recharge-ok', function() {
		moneyStart1 = Number($('#money-start').text());
		moneyEnd1 = moneyStart1 + Number($('#recharge-money').val());
		moneyStart2 = Number($('#amount1').text());
		moneyEnd2 = moneyStart2 + Number($('#recharge-money').val());

		// $('.remainder').text(Number($('.remainder').text()) - );
		$('#recharge .alert-success').css('display', 'block');
		$('#recharge').on('hidden.bs.modal', function(e) {
			// do something...
			$('#recharge .alert-success').css('display', 'none');

			count1 = new countUp('money-start', moneyStart1, moneyEnd1, 2, 2.5, options);
			count1.start();

			count2 = new countUp('amount1', moneyStart2, moneyEnd2, 2, 2.5, options);
			count2.start();

			data[0].value = moneyEnd2;
			$('#donut-main').empty();
			donut();
		});
		getCurrentDate();
		tr = '<tr>' +
			'<td>' + year + '.' + month + '.' + day + ' ' + hour + ':' + minute + ':' + second + '</td>' +
			'<td>充值</td>' +
			'<td class="green">收入</td>' +
			'<td>' + Number($('#recharge-money').val()).toFixed(2) + '</td>' +
			'<td>中国银行 ...5943</td>' +
			'<td>成功</td>' +
			'</tr>';
		$('#tab2').find('tbody').prepend(tr);
	});

	// 提现
	$('body').on('click', '#withdraw-cash .btn-warning', function() {
		moneyStart1 = Number($('#money-start').text());
		moneyEnd1 = moneyStart1 - Number($('#withdraw-money').val());
		moneyStart3 = Number($('#amount2').text());
		moneyEnd3 = moneyStart3 + Number($('#withdraw-money').val());

		$('#withdraw-cash .alert-success').css('display', 'block');
		$('#withdraw-cash').on('hidden.bs.modal', function(e) {
			// do something...
			$('#withdraw-cash .alert-success').css('display', 'none');

			count1 = new countUp('money-start', moneyStart1, moneyEnd1, 2, 2.5, options);
			count1.start();

			count3 = new countUp('amount2', moneyStart3, moneyEnd3, 2, 2.5, options);
			count3.start();

			data[1].value = moneyEnd3;
			$('#donut-main').empty();
			donut();
		});
		getCurrentDate();
		tr = '<tr>' +
			'<td>' + year + '.' + month + '.' + day + ' ' + hour + ':' + minute + ':' + second + '</td>' +
			'<td>提现</td>' +
			'<td class="orange">支出</td>' +
			'<td>' + Number($('#withdraw-money').val()).toFixed(2) + '</td>' +
			'<td>中国银行 ...5943</td>' +
			'<td>成功</td>' +
			'</tr>';
		$('#tab3').find('tbody').prepend(tr);
	});


	// var donut = new Morris.Donut({
	// 	element: 'donut-main',
	// 	data: data,
	// 	colors: ['#EF8100', '#FEC99B', '#FFAA62', '#A85623', '#C14E00']
	// });

	//鼠标触发事件
	$("#donut-info").on("mouseenter", "li", function() {
		$(this).css("marginLeft", "-15px");
		if ($("#donut-main").find("svg").length > 0) {
			donutM.select($(this).index());
		}
	});

	$("#donut-info").on("mouseleave", "li", function() {
		$(this).css("marginLeft", "0px");
	});


});